package cn.zzf.core;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * @author GaoFeng2017
 * @date 2018-02-20 11:08:23
 **/

public class DataParse {
    protected File dataFileRoot;
    protected List<Properties> dataFiles;

    protected DataParse(File dataFileRoot) {
        this.dataFileRoot = dataFileRoot;
        initDataFiles();
    }

    protected void initDataFiles() {
        if (this.dataFileRoot != null) {
            File[] fs = dataFileRoot.listFiles();
            dataFiles = new ArrayList<Properties>(fs.length);
            InputStreamReader reader = null;
            for (File f : fs) {
                try {
                    reader = new InputStreamReader(new FileInputStream(f), "utf-8");
                    Properties properties = new Properties();
                    properties.load(reader);
                    dataFiles.add(properties);
                } catch (Exception e) {
                    throw new ExceptionInInitializerError(e);
                }
            }
        }
    }

    /*getter and setter*/
    public File getDataFileRoot() {
        return dataFileRoot;
    }

    public void setDataFileRoot(File dataFileRoot) {
        this.dataFileRoot = dataFileRoot;
    }
}
